<template>
  <a-list
    item-layout="horizontal"
    :data-source="data"
    style="max-height:250px;overflow-y: auto;"
  >
    <div
      v-if="showLoadingMore"
      slot="loadMore"
      :style="{ textAlign: 'center', marginTop: '12px', height: '32px', lineHeight: '32px' }"
    >
      <a-spin v-if="loadingMore" />
      <div v-if="!loadingMore && data.length>0">
        <a-button v-if="ipagination.pageNo < ipagination.pages" @click="onLoadMore" type="link">
          加载更多
        </a-button>
        <a-button v-else type="link">
          暂无更多
        </a-button>
      </div>
    </div>
    <a-list-item slot="renderItem" slot-scope="item, index">
      <a-list-item-meta
        :description="'修改字段'+item.fieldName+':'+item.oldValue +' -> ' + item.newValue"
      >
        <a slot="title">{{item.createTime +'    '+ item.createBy }}</a>
        <a-avatar slot="avatar" icon="sound"/>
      </a-list-item-meta>
    </a-list-item>
  </a-list>
</template>
<script >
import { getAction } from '@/api/manage'
export default {
  name: 'Projectlog',
  data() {
    return {
      data: [],
      showLoadingMore: true,
      loadingMore: false,
      ipagination: {
        pageNo: 1,
        pageSize: 5,
        pages: 1
      }
    }
  },
  props: ['projectCode', 'param'],
  watch: {
    // projectCode(val) {
    //   this.ipagination = {
    //     pageNo: 1,
    //     pageSize: 5,
    //     pages: 1
    //   }
    //   if (val) {
    //     this.loadProjectlog()
    //   } else {
    //     this.data = []
    //   }
    // },
    // param: {
    //   handler: function(newValue, oldValue) {
    //     this.ipagination = {
    //       pageNo: 1,
    //       pageSize: 5,
    //       pages: 1
    //     }
    //     console.log(this.projectCode)
    //     if (this.projectCode) {
    //       this.loadProjectlog()
    //     } else {
    //       this.data = []
    //     }
    //   },
    //   deep: true
    // }
  },
  mounted() {
    if (this.param && this.param.projectCode) {
      this.loadProjectlog()
    } else {
      this.data = []
    }
  },
  methods: {
    loadProjectlog() {
      var param = Object.assign(this.param, this.ipagination)
      getAction('/pms/projectlog/list', param).then(res => {
        if (res.success) {
          this.data = this.data.concat(res.result.records)
          this.ipagination.pages = res.result.pages
        }
      })
    },
    onLoadMore() {
      this.ipagination.pageNo++
      this.loadProjectlog()
    }
  }
}
</script>
<style lang='scss'>
</style>
